/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-06-03 11:25:22
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-06-03 11:25:31
 * @FilePath: \project\record-work-time\uniCloud-aliyun\cloudfunctions\JWT\login.js
 * @Description: 
 */
// 登录函数，生成JWT
const jwt = require('jwt-provider');
 
exports.main = async (event, context) => {
  const user = await authenticateUser(event); // 用户认证逻辑
  if (user) {
    const token = jwt.createToken({ uid: user._id });
    return {
      code: 200,
      token: token
    };
  } else {
    return {
      code: 401,
      errMsg: '认证失败'
    };
  }
};